home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 2627 < prev    next >
Encoding:
Text File  |  1996-08-06  |  2.0 KB  |  57 lines

  1. Path: hub.ymi.com!news
  2. From: Jeffrey Keays <keays@ymi.com>
  3. Newsgroups: comp.lang.c++,comp.os.ms-windows.programmer.tools.mfc
  4. Subject: Newbie question: default op=
  5. Date: Thu, 18 Jan 1996 11:34:12 -0800
  6. Organization: Young Minds, Inc.
  7. Message-ID: <30FEA0B4.4F66@ymi.com>
  8. NNTP-Posting-Host: 192.111.121.191
  9. Mime-Version: 1.0
  10. Content-Type: text/plain; charset=us-ascii
  11. Content-Transfer-Encoding: 7bit
  12. X-Mailer: Mozilla 2.0b5 (WinNT; I)
  13.  
  14. I am trying to use the &*%$ MFC collections in some way that will dispose of its contents on destruction.  In 
  15. my 2-days and counting of ramming my head repeatedly against this brick wall over something that should be made 
  16. 'easier' by them, I have this general C++ question.
  17.  
  18. Why is it making me create operator= functions for assignment of the same type (or instance / reference of the 
  19. same type).  The class I'm trying to assign has no pointers or anything that would require special handling.  
  20. Why do I have to write stupid things like
  21.  
  22. class foo {
  23.     int data1;
  24.     double data2;
  25.     CString data3;
  26.     // ... ad infinitum
  27. public:
  28.     foo& operator=(const foo &);
  29. }
  30.  
  31. foo& foo::operator=(const foo &rhs)
  32. {
  33.     data1 = rhs.data1
  34.     data2 = rhs.data2
  35.     data3 = rhs.data3
  36.     // ... -- I should not have to write this, it should be ASSUMED 
  37.     //        by the compiler if I don't specify otherwise.
  38. }
  39.  
  40. The class i'm actually using is "Job", it has no data members that don't have their own appliance-ized helper 
  41. functions (CString) or are simple types.  The collection is "CList<Job, Job&> joblist", and here is my line
  42.  
  43.     joblist.AddTail(Job(p, wfd.cFileName));
  44.  
  45. This is the line in MFC with the complaint,
  46.  
  47.     pNewNode->data = newElement;
  48.  
  49. and this is the error.
  50.  
  51. F:\MSDEV\MFC\include\afxtempl.h(813) : error C2582: 'Job' : 'operator =' function is unavailable
  52.  
  53. Job has a two-argument constructor, as well as a do-nothing empty constructor I was forced against my will to 
  54. add (I have found it documented that if you define any constructors, you lose the default constructor -- I have 
  55. taken this as a given, since I don't know the rationale.)
  56. --
  57.